<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>登录页面-用户门户登录</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/materialdesignicons.min.css" rel="stylesheet">
    <link href="../css/style.min.css" rel="stylesheet">
    <style>
        .lyear-wrapper {
            position: relative;
        }
        .lyear-login {
            display: flex !important;
            min-height: 100vh;
            align-items: center !important;
            justify-content: center !important;
        }
        .lyear-login:after{
            content: '';
            min-height: inherit;
            font-size: 0;
        }
        .login-center {
            background: #fff;
            min-width: 29.25rem;
            padding: 2.14286em 3.57143em;
            border-radius: 3px;
            margin: 2.85714em;
        }
        .login-header {
            margin-bottom: 1.5rem !important;
        }
        .login-center .has-feedback.feedback-left .form-control {
            padding-left: 38px;
            padding-right: 12px;
        }
        .login-center .has-feedback.feedback-left .form-control-feedback {
            left: 0;
            right: auto;
            width: 38px;
            height: 38px;
            line-height: 38px;
            z-index: 4;
            color: #dcdcdc;
        }
        .login-center .has-feedback.feedback-left.row .form-control-feedback {
            left: 15px;
        }
    </style>
</head>

<body>
<div class="row lyear-wrapper" style="background-image: url(../images/login-bg-3.jpg); background-size: cover;">
    <div class="lyear-login">
        <div class="login-center" style="width: 500px">
            <div class="login-header text-center">
                <a href="user_login.jsp"> <img alt="light year admin" src="../images/logo-sidebar.png"> </a>
            </div>
            <form action="#!" method="post" id="formLogin">
                <div class="form-group has-feedback feedback-left">
                    <input type="text" placeholder="请输入您的用户名" class="form-control" name="username" id="username" />
                    <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group has-feedback feedback-left">
                    <input type="password" placeholder="请输入密码" class="form-control" id="password" name="password" />
                    <span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group">
                    <button id="btn_login" class="btn btn-block btn-primary" type="button">立即登录</button>
                    <hr>
                    <button class="btn btn-block btn-primary" type="button" onclick="location.href='user/user_register.jsp'">注  册</button>
                </div>
            </form>
            <hr>
        </div>
    </div>
</div>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/myScript/app.js"></script>
<script type="text/javascript">

    $("#btn_login").on("click", function () {
        var adminAccount = $("#username").val();
        var adminPassword = $("#password").val();
        if (adminAccount === "" || adminAccount == null || adminAccount.length < 6 || adminAccount.length >= 15) {
            alert("账号输入不合法！");
            return;
        }
        if(adminPassword === "") {
            alert("密码不能为空");
            return;
        }
        $.ajax({
            type: "POST",
            contentType: "application/json;charset=urf-8",
            url: serverUrl + "/user/userLogin",
            dataType: "json",
            data: JSON.stringify({"pnAccount": adminAccount, "pnPassword":adminPassword}),
            xhrFields: {
                withCredentials: true
            },
            success: function (res, status, xhr) {
                if (res.success) {
                    //将数据存储到sessionStore中
                    sessionStorage.setItem("user", JSON.stringify(res.data));
                    window.location.href="http://localhost:8081/user/gsjj.jsp";
                } else {
                    alert(res.msg);
                }
            },
            error: function (res) {
                alert("服务器请求不成功")
            }
        })



    })

</script>
</body>
</html>
